package com.cx.purchase.spare.controller;

import com.cx.purchase.config.ResultVO;
import com.cx.purchase.config.ResultVOBuilder;
import com.cx.purchase.spare.model.*;
import com.cx.purchase.spare.service.SpareSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@CrossOrigin
public class SpareController {
    @Autowired
    private SpareSerivce spareSerivce;

   @PostMapping("materialCostPrice/queryPage")
    public ResultVO queryPage(@RequestBody SpareSelectVo spareSelectVo){
        return spareSerivce.queryPage(spareSelectVo);
    }

    @GetMapping("materialCostPrice/queryAllTaxType")
    private ResultVO queryAllTaxType(){


        return spareSerivce.queryAllTaxType();
    }

    @GetMapping("materialCostPrice/queryPlantListByLegalPersonCode")
    private ResultVO queryPlantListByLegalPersonCode( SelectByLegalPersonCode selectByLegalPersonCode){


        return spareSerivce.queryPlantListByLegalPersonCode(selectByLegalPersonCode);
    }

    @PostMapping("metadata/getPullDownList1")
    private ResultVO getPullList(){
        return spareSerivce.queryPullList();
    }

    @PostMapping("material/searchEnabled")
    private ResultVO searchEnabled(@RequestBody SpareLiSelectVo spareLiSelectVo){
        return spareSerivce.searchEnabled(spareLiSelectVo);
    }
    @PostMapping("materialCostPrice/add")
    private ResultVO add(@RequestBody SpareAdd spareAdd){
        System.out.println(spareAdd);
       return spareSerivce.add(spareAdd);
    }

    @PostMapping("materialCostPrice/updateStatus")
    private ResultVO updateStatus(@RequestBody SpareUpdateStatus spareUpdateStatus){
        return spareSerivce.updateStatus(spareUpdateStatus);
    }
    @PostMapping("materialCostPrice/update")
    private ResultVO update(@RequestBody SpareUpdate spareUpdate){
        System.out.println();
        return spareSerivce.update(spareUpdate);
    }

    //导入
    @PostMapping("SparePartsCost/SparePartsCostIntroduction")
    public ResultVO importFile(MultipartFile file,SpareAdd spareAdd)throws Exception{
        System.out.println(file.getOriginalFilename());
        if (!file.getOriginalFilename().contains("xlsx")){
            return ResultVOBuilder.error("请检查导入模板，尾缀名必须为xlsx");
        }

        ResultVO resultVO = spareSerivce.importFile(file,spareAdd);

        return ResultVOBuilder.success(resultVO);

    }




}

